<template>
	<view>
		<cu-custom class="text-Black" bgColor="bg-red" :isBack="true">		<block slot="content">公告列表</block>
		</cu-custom>
		<view class="cu-card article">
			<view class="cu-item shadow padding-sm" v-for="(item,index) in list" :key="index" @tap="goDetail(item)">
				<view class="space-between align-center">
					<view class="text-bold text-cut">{{item.title}}</view>
					<view class="text-gray text-right" style="min-width: 200rpx;">
						<text v-if="item.created_at > 0">{{$common.timeFormat(item.created_at,'YYYY-MM-DD')}}</text>
					</view>
				</view>
				<view class="text-cut text-grey radius margin-tb-sm">{{item.description}}</view>
				<view class="space-between">
					<view class="">{{item.author}}</view>
					<view class=" text-gray">查看详情
						<text class="cuIcon-right lg text-gray"></text>
					</view>
				</view>
			</view>
		</view>

		<view class="cu-load margin-center" :class="loading?'loading':'over'"></view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				cate_id: 1,
				list: [],
				hasMore: true,
				page: 1,
				loading: false
			};
		},
		onLoad(options) {
			this.getList()
		},
		methods: {
			getList() {
				if (this.hasMore && !this.loading) {
					this.hasMore = false
					this.loading = true
					this.$http
						.get('article_index', {
							cate_id: this.cate_id,
							page: this.page,
						})
						.then((response) => {
							let list = this.list
							if (response.data.data.length > 0) {
								list = list.concat(response.data.data)
							} else {
								this.hasMore = false
							}
							this.list = list
							this.loading = false
						})
						.catch((response) => {
							console.log(response)
						})
				}
			},
			goDetail: function(item) {
				uni.navigateTo({
					url: "/pages/site/article_detail?id=" + item.id
				})
			}
		},
		onReachBottom() {
			this.getList()
		},
	}
</script>

<style>
	.main-view {
		height: 100vh;
	}
</style>
